#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <stdio.h>
#include <iostream>

using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    bool isCompleteTree(TreeNode* root) {
        if (root == nullptr) return false;
        if (root->left == nullptr && root->right == nullptr) return true;
        
        TreeNode *cur = root;
        stack<TreeNode*> s;
        int cur_h = 1;
        stack<int> height_s;
        int first_pop = 1;
        int most_left_node_height = 0;
        int no_more_right_node = 0;
        
        while (!s.empty() || cur != nullptr) {
            while (cur != nullptr) {
                if (most_left_node_height != 0 && cur_h > most_left_node_height) {
                    printf("=-= cur value: %d height %d beyond max height: %d\n",
                            cur->val, cur_h, most_left_node_height);
                    return false;
                }
                if (no_more_right_node && cur_h == most_left_node_height) {
                    printf("=-= find node %d at the illegal location on the right\n", cur->val);
                    return false;
                }
                s.push(cur);
                height_s.push(cur_h);
                cur = cur->left;
                cur_h++;
            }
            if (first_pop) {
                most_left_node_height = height_s.top();
                first_pop = 0;
                printf("=-= most_left_node_height: %d(h:%d)\n", s.top()->val, most_left_node_height);
            }
            if (cur_h < most_left_node_height) {
                printf("=-= null node (h:%d) less than most left height %d\n", cur_h, most_left_node_height);
                return false;
            }
            if (cur_h == most_left_node_height) {
                no_more_right_node = 1;
                printf("=-= no more node on the right of %d\n", s.top()->val);
            }
            cur = s.top()->right;
            cur_h = height_s.top() + 1;
            printf("=-= pop %d(h:%d)->right\n", s.top()->val, height_s.top());
            if (cur != nullptr && cur_h > most_left_node_height) {
                printf("=-= cur value: %d height %d beyond max height: %d\n",
                      cur->val, cur_h, most_left_node_height);
                return false;
            }
            if (cur != nullptr && cur_h == most_left_node_height && no_more_right_node) {
                printf("=-= find node %d at the illegal location on the right\n", cur->val);
                return false;
            }
            if (cur == nullptr && cur_h == most_left_node_height) {
                no_more_right_node = 1;
                printf("=-= no more node on the right of %d\n", s.top()->val);
            }
            if (cur == nullptr && cur_h < most_left_node_height) {
                printf("=-= null node (h:%d) less than most left height %d\n", cur_h, most_left_node_height);
                return false;
            }
            
            s.pop();
            height_s.pop();
        }
        return true;
    }
};

void trimLeftTrailingSpaces(string &input) {
    input.erase(input.begin(), find_if(input.begin(), input.end(), [](int ch) {
                return !isspace(ch);
                }));
}

void trimRightTrailingSpaces(string &input) {
    input.erase(find_if(input.rbegin(), input.rend(), [](int ch) {
                return !isspace(ch);
                }).base(), input.end());
}

TreeNode* stringToTreeNode(string input) {
    input = input.substr(1, input.length() - 2);
    if (!input.size()) {
        return nullptr;
    }

    string item;
    stringstream ss;
    ss.str(input);

    getline(ss, item, ',');
    TreeNode* root = new TreeNode(stoi(item));
    queue<TreeNode*> nodeQueue;
    nodeQueue.push(root);

    while (true) {
        TreeNode* node = nodeQueue.front();
        nodeQueue.pop();

        if (!getline(ss, item, ',')) {
            break;
        }

        trimLeftTrailingSpaces(item);
        if (item != "null") {
            int leftNumber = stoi(item);
            node->left = new TreeNode(leftNumber);
            nodeQueue.push(node->left);
        }

        if (!getline(ss, item, ',')) {
            break;
        }

        trimLeftTrailingSpaces(item);
        if (item != "null") {
            int rightNumber = stoi(item);
            node->right = new TreeNode(rightNumber);
            nodeQueue.push(node->right);
        }
    }
    return root;
}

string boolToString(bool input) {
    return input ? "True" : "False";
}

int main() {
    string line;
    while (getline(cin, line)) {
        TreeNode* root = stringToTreeNode(line);
        
        bool ret = Solution().isCompleteTree(root);

        string out = boolToString(ret);
        cout << out << endl;
    }
    return 0;
}
